/**************************************************************************
 *         Copyright(c) 2007 by Sunplus mMedia  Technology Co., Ltd.       *
 *                                                                         *
 *  This software is copyrighted by and is the property of Sunplus mMedia  *
 *  Technology Co., Ltd. All rights are reserved by Sunplus mMedia Techno- *
 *  logy Co., Ltd. This software may only be used in accordance with the   *
 *  corresponding license agreement. Any unauthorized use, duplication,    *
 *  distribution, or disclosure of this software is expressly forbidden.   *
 *                                                                         *
 *  This Copyright notice "M U S T" not be removed or modified without     *
 *  prior written consent of Sunplus mMedia Technology  Co., Ltd.          *
 *                                                                         *
 *  Sunplus mMedia Technology Co., Ltd. reserves the right to modify this  *
 *  software without notice.                                               *
 *                                                                         *
 *  Sunplus mMedia Technology Co., Ltd.                                    *
 *  19-1, Innovation First Road, Science-Based Industrial Park,            *
 *  Hsin-Chu, Taiwan, R.O.C.                                               *
 *                                                                         *
 **************************************************************************/
#include "general.h"
#include "app_main.h"
#include "os_msg.h"
#include "app_osd_icon.h"
#include "app_ui_osd.h"
#include "app_menu.h"
#include "app_menu_api.h"
#include "app_menu_core.h"
#include "app_menu_tab.h"
#include "app_menu_micro.h"
#include "App_ui_para.h"
#include "app_still_play.h"
#include "sp1k_disp_api.h"
#include "sp1k_pb_api.h"
#include "sp1k_osd_api.h"
#include "app_ui_power.h"
#include "initio.h"
#include "smcfunc.h"

/**************************************************************************
 *                           C O N S T A N T S                            *
 **************************************************************************/

/**************************************************************************
 *                           C O N S T A N T S                            *
 **************************************************************************/
#define	MENU_TAB_GET_FOCUS		(OSD_ATTR_COLOR_CYAN | OSD_ATTR_MODE_EXCHANGE | OSD_ATTR_BACK_EN)
#define	MENU_TAB_LOST_TFOCUS	(OSD_ATTR_COLOR_BLACK | OSD_ATTR_MODE_NOMAL | OSD_ATTR_BACK_DIS)
#define	MENU_TAB_DISABLE		(OSD_ATTR_COLOR_BLACK | OSD_ATTR_MODE_NOMAL | OSD_ATTR_BACK_DIS)

#define	MENU_STR_GET_FOCUS		(OSD_ATTR_COLOR_CYAN | OSD_ATTR_MODE_EXCHANGE | OSD_ATTR_BACK_EN)
#define	MENU_STR_LOST_FOCUS		(OSD_ATTR_COLOR_WHITE | OSD_ATTR_MODE_HALFTONE | OSD_ATTR_BACK_EN)
#define	MENU_STR_DISABLE		(OSD_ATTR_COLOR_RED | OSD_ATTR_MODE_HALFTONE | OSD_ATTR_BACK_EN)

#define	MENU_ICON_GET_FOCUS		(OSD_ATTR_COLOR_CYAN | OSD_ATTR_MODE_HALFTONE | OSD_ATTR_BACK_EN)
#define	MENU_ICON_LOST_FOCUS	(OSD_ATTR_COLOR_WHITE | OSD_ATTR_MODE_HALFTONE | OSD_ATTR_BACK_EN)
#define	MENU_ICON_DISABLE		(OSD_ATTR_COLOR_RED | OSD_ATTR_MODE_HALFTONE | OSD_ATTR_BACK_EN)

#define	MENU_PROMPT_GET_FOCUS	(OSD_ATTR_COLOR_WHITE| OSD_ATTR_MODE_NOMAL | OSD_ATTR_BACK_DIS)
#define	MENU_PROMPT_LOST_FOCUS	(OSD_ATTR_COLOR_WHITE | OSD_ATTR_MODE_NOMAL | OSD_ATTR_BACK_DIS)
#define	MENU_PROMPT_DISABLE		(OSD_ATTR_COLOR_WHITE | OSD_ATTR_MODE_NOMAL | OSD_ATTR_BACK_DIS)

#define MENU_PROMPT_OK_OFF	0x00
#define MENU_PROMPT_MENU_OFF	0x00

#define MENU_PROMPT_OK_ON	0x01
#define MENU_PROMPT_MENU_ON	0x02

#define MENU_HEADER_OFF		0x00
#define MENU_HEADER_SETUP	0x01
#define MENU_HEADER_FUNCTION	0x02

/**************************************************************************
 *                         G L O B A L    D A T A                         *
 **************************************************************************/
static UINT8 menuXOff=1;
static UINT8 menuYOff=1;
UINT32 menuPosBackup;

UINT16 idxBuf[256];
UINT8  attrBuf[256];

/**************************************************************************
 *               F U N C T I O N    D E C L A R A T I O N S               *
 **************************************************************************/
//"MM/DD/YYYY",
//"DD/MM/YYYY",
//"YYYY/MM/DD",
UINT8 code rtc_disp[3][6]={{1, 2, 0, 3, 4, 5}, {2, 1, 0, 3, 4, 5}, {0, 1, 2, 3, 4, 5}};
UINT8 code exposure[]="\x1c\x1d\x1d\x1c\x1d\x1d\x1c\x1d\x1d\x1c\x1d\x1d\x1c";
UINT8 code chinese_s[]={(ID_ICON_JIAN<<1) >> 8, (ID_ICON_JIAN<<1) & 0xff,((ID_ICON_JIAN<<1) + 1)>> 8, ((ID_ICON_JIAN<<1) + 1) & 0xff,
						(ID_ICON_TI_S<<1) >> 8, (ID_ICON_TI_S<<1) & 0xff,((ID_ICON_TI_S<<1) + 1)>> 8, ((ID_ICON_TI_S<<1) + 1) & 0xff,
						(ID_ICON_ZHONG<<1) >> 8, (ID_ICON_ZHONG<<1) & 0xff,((ID_ICON_ZHONG<<1) + 1)>> 8, ((ID_ICON_ZHONG<<1) + 1) & 0xff,
						(ID_ICON_WEN<<1) >> 8, (ID_ICON_WEN<<1) & 0xff,((ID_ICON_WEN<<1) + 1)>> 8, ((ID_ICON_WEN<<1) + 1) & 0xff,'\0','\0',
};
UINT8 code chinese_t[]={(ID_ICON_FAN<<1) >> 8, (ID_ICON_FAN<<1) & 0xff,((ID_ICON_FAN<<1) + 1)>> 8, ((ID_ICON_FAN<<1) + 1) & 0xff,
						(ID_ICON_TI_T<<1) >> 8, (ID_ICON_TI_T<<1) & 0xff,((ID_ICON_TI_T<<1) + 1)>> 8, ((ID_ICON_TI_T<<1) + 1) & 0xff,
						(ID_ICON_ZHONG<<1) >> 8, (ID_ICON_ZHONG<<1) & 0xff,((ID_ICON_ZHONG<<1) + 1)>> 8, ((ID_ICON_ZHONG<<1) + 1) & 0xff,
						(ID_ICON_WEN<<1) >> 8, (ID_ICON_WEN<<1) & 0xff,((ID_ICON_WEN<<1) + 1)>> 8, ((ID_ICON_WEN<<1) + 1) & 0xff,'\0','\0',
};

/**************************************************************************
 *                 E X T E R N A L    R E F E R E N C E S                 *
 **************************************************************************/
//extern UINT8 OsdMaxX;
//extern UINT8 OsdMaxY;
//extern UINT8 OsdMaxNum;
extern SIMAGE xdata pbFile;

/**************************************************************************
 *                                                                        *
 *  Function Name: menuLanguageGet                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments: None                                                       *
 *                                                                        *
 *  Returns:                                                              *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
UINT8 menuLanguageGet(void)
{
	uiPara_t* puiPara = appUiParaGet();

	if (puiPara->Language >= LANGUAGE_MAX)
		puiPara->Language = ENGLISH;

	return puiPara->Language;
}

/**************************************************************************
 *                                                                        *
 *  Function Name: menuDateItemConv                                       *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments: None                                                       *
 *                                                                        *
 *  Returns:                                                              *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
UINT8 menuDateItemConv(UINT8 item)
{
	uiPara_t* puiPara = appUiParaGet();

	return rtc_disp[puiPara->DateStyle][item];
}

/**************************************************************************
 *                                                                        *
 *  Function Name: menuDateItemConv                                       *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments: None                                                       *
 *                                                                        *
 *  Returns:                                                              *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
void menuDayItemCheck(UINT8 item, UINT8 key)
{
	UINT8 dayMax;
	uiPara_t* puiPara = appUiParaGet();

	switch(puiPara->rtcMonth+1)
	{
		case 2:
		//modify for leep year problem @2008-04-11 wei.sun begin
		//if ((puiPara->rtcYear) && (!(puiPara->rtcYear & 0x03)))
		if (!(puiPara->rtcYear & 0x03))
		//modify for leep year problem @2008-04-11 wei.sun end
			dayMax = 28;
		else
			dayMax = 27;
		if (puiPara->rtcDay > dayMax)
		{
			if ((item == 2) && (key == SP1K_MSG_KEY_PRESS_UP))
				puiPara->rtcDay = 0;
			else
				puiPara->rtcDay = dayMax;
		}
		break;

		case 4:
		case 6:
		case 9:
		case 11:
		dayMax = 29;
		if (puiPara->rtcDay > dayMax)
		{
			if ((item == 2) && (key == SP1K_MSG_KEY_PRESS_UP))
				puiPara->rtcDay = 0;
			else
				puiPara->rtcDay = dayMax;
		}
		break;
	}
	if(puiPara->rtcYear == 7 && key == SP1K_MSG_KEY_PRESS_DOWN)
		puiPara->rtcYear = 30;
	if(puiPara->rtcYear == 0 && key == SP1K_MSG_KEY_PRESS_UP)
		puiPara->rtcYear = 8;
	
}

/**************************************************************************
 *                                                                        *
 *  Function Name: menuLayerSizeGet                                       *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments: None                                                       *
 *                                                                        *
 *  Returns:                                                              *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
void menuLayerSizeGet(UINT8 layer, UINT8* line, UINT8* col)
{
	UINT8 OsdMaxX, OsdMaxY;

	sp1kOsdLayoutAttrGet(&OsdMaxX, &OsdMaxY);

	if (layer < 4)
	{
		*col = OsdMaxX - 2;
		*line = OsdMaxY - 2;
	}
	else
	{
		*col = OsdMaxX;
		*line = OsdMaxY ;
	}
}

/**************************************************************************
 *                                                                        *
 *  Function Name: menuStrDisp                                            *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments: None                                                       *
 *                                                                        *
 *  Returns:                                                              *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
UINT8 menuStrDisp(UINT8 x, UINT8 y, UINT8* str, UINT8 lgh, UINT8 attr)
{
	UINT8	addr;
	UINT8	i;
	UINT16*	pstr16=(UINT16*)str;
	UINT8 OsdMaxX, OsdMaxY;

	sp1kOsdLayoutAttrGet(&OsdMaxX, &OsdMaxY);

	if (lgh == 0)
		lgh = 255;

	addr = OsdMaxX * (menuYOff+y) + (menuXOff+x);

	if (str[0] > 2)
	{
		for (i=0; i<lgh; i++,addr++)
		{
			if (str[i] == '\0')
				break;
			idxBuf[addr] = (UINT16)(str[i]);
			attrBuf[addr] = attr;
		}
	}
	else
	{
		for (i=0; i<lgh; i++,addr++)
		{
			if (pstr16[i] == '\0')
				break;
			idxBuf[addr] = (UINT16)(pstr16[i]);
			attrBuf[addr] = attr;
		}
	}

	if (lgh == 255)
		return i;

	for (; i<lgh; i++,addr++)
	{
		idxBuf[addr] = (UINT16)' ';
		attrBuf[addr] = attr;
	}

	return i;
}

/**************************************************************************
 *                                                                        *
 *  Function Name: menuIconDisp                                           *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments: None                                                       *
 *                                                                        *
 *  Returns:                                                              *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
void menuIconDisp(UINT8 x, UINT8 y, UINT8 icon, UINT8 attr)
{
	UINT8 addr;
	UINT8 OsdMaxX, OsdMaxY;

	sp1kOsdLayoutAttrGet(&OsdMaxX, &OsdMaxY);

	addr = OsdMaxX * (menuYOff+y) + (menuXOff+x);

	if (icon == ID_ICON_NONE)
	{
		idxBuf[addr] = ' ';
		attrBuf[addr] = attr;

		addr++;
		idxBuf[addr] = ' ';
		attrBuf[addr] = attr;
	}
	else
	{
		idxBuf[addr] = (UINT16)icon * 2;
		attrBuf[addr] = attr;

		addr++;
		idxBuf[addr] = (UINT16)icon * 2 + 1;
		attrBuf[addr] = attr;
	}
}

/**************************************************************************
 *                                                                        *
 *  Function Name: menuHeaderDisp                                         *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments: None                                                       *
 *                                                                        *
 *  Returns:                                                              *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
void menuHeaderDisp(attr)
{
	sp1kDispCapabDesc_t dispCap;
	UINT8	icon;
	UINT8	xoff;
	UINT8	yoff;
	uiPara_t* puiPara;

	xoff = menuXOff;
	yoff = menuYOff;
	menuXOff=0;
	menuYOff=0;

	puiPara = appUiParaGet();
	sp1kDispCapabilityGet(sp1kDispDevActGet(), &dispCap);
	if (attr == MENU_HEADER_OFF) {
		sp1kOsdSelWinSet(16 - 5, 32, dispCap.width - 2 * 16 + 10, dispCap.height - 2 * 32, 0, OSD_ATTR_COLOR_CYAN);
	}
	else if (attr == MENU_HEADER_SETUP) {
		icon = menuProcIconIDGetByPos(menuPosBackup);
		menuIconDisp(2, 0, icon, MENU_TAB_LOST_TFOCUS);

		icon = menuProcIconIDGetByPos(MENU_MARK_SETUP);
		menuIconDisp(5, 0, icon, MENU_TAB_GET_FOCUS);

		menuStrDisp(4, 0, "\x1e", 1, OSD_ATTR_COLOR_CYAN);
		menuStrDisp(7, 0, "\x1f", 1, OSD_ATTR_COLOR_CYAN);
		menuStrDisp(1, 0, " ", 1, OSD_ATTR_COLOR_CYAN);
		if (appPanelTypeGet() == 1) {
			sp1kOsdSelWinSet(16 - 6, 32, dispCap.width - 2 * 16 + 16 -2, dispCap.height - 2 * 32, 5, OSD_ATTR_COLOR_CYAN);
		}
		else {
			if (puiPara->TVMode == TVMODE_NTSC) {
				sp1kOsdSelWinSet(16-3, 32+32-14, dispCap.width - 2*2 * 16 + 16, dispCap.height - 3 * 32, 5, OSD_ATTR_COLOR_CYAN);
			}
			else {
				sp1kOsdSelWinSet(16-3, 32+32-16, dispCap.width - 2*2 * 16 + 16, dispCap.height - 3 * 32 -12, 5, OSD_ATTR_COLOR_CYAN);
			}
		}
	}
	else {  /* MENU_HEADER_FUNCTION */
		icon = menuProcIconIDGetByPos(menuPosBackup);
		menuIconDisp(2, 0, icon, MENU_TAB_GET_FOCUS);

		icon = menuProcIconIDGetByPos(MENU_MARK_SETUP);
		menuIconDisp(5, 0, icon, MENU_TAB_LOST_TFOCUS);

		menuStrDisp(1, 0, "\x1e", 1, OSD_ATTR_COLOR_CYAN);
		menuStrDisp(4, 0, "\x1f", 1, OSD_ATTR_COLOR_CYAN);
		menuStrDisp(7, 0, " ", 1, OSD_ATTR_COLOR_CYAN);
		if (appPanelTypeGet() == 1) {
			sp1kOsdSelWinSet(16 - 6, 32, dispCap.width - 2 * 16 + 16 -2, dispCap.height - 2 * 32, 5, OSD_ATTR_COLOR_CYAN);
		}
		else {
			if (puiPara->TVMode == TVMODE_NTSC) {
				sp1kOsdSelWinSet(16-3, 32+32-14, dispCap.width - 2*2 * 16 + 16, dispCap.height - 3 * 32, 5, OSD_ATTR_COLOR_CYAN);
			}
			else {
				sp1kOsdSelWinSet(16-3, 32+32-16, dispCap.width - 2*2 * 16 + 16, dispCap.height - 3 * 32-12, 5, OSD_ATTR_COLOR_CYAN);
			}
		}
	}

	menuXOff=xoff;
	menuYOff=yoff;
}

/**************************************************************************
 *                                                                        *
 *  Function Name: menuPromptDisp                                         *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments: None                                                       *
 *                                                                        *
 *  Returns:                                                              *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
void menuPromptDisp(attr)
{
	sp1kDispCapabDesc_t dispCap;
	UINT8	line, col;
	UINT8	xoff;
	UINT8	yoff;
	UINT8 OsdMaxX, OsdMaxY;

	sp1kOsdLayoutAttrGet(&OsdMaxX, &OsdMaxY);

	xoff = menuXOff;
	yoff = menuYOff;
	menuXOff=0;
	menuYOff=0;

	sp1kDispCapabilityGet(sp1kDispDevActGet(), &dispCap);
	line = OsdMaxY;
	col = OsdMaxX;

	#if 1
	if (attr & MENU_PROMPT_OK_ON)
	{
		menuIconDisp(2, line-1, ID_ICON_ARROW_OK, MENU_PROMPT_GET_FOCUS);
		menuStrDisp(4, line-1, menuStrGet(ID_STR_ENTER), 0, MENU_PROMPT_GET_FOCUS);
	}
	if (attr & MENU_PROMPT_MENU_ON)
	{
		menuIconDisp(col-6-2, line-1, ID_ICON_ARROW_MENU, MENU_PROMPT_GET_FOCUS);
		menuStrDisp(col-4-2, line-1, menuStrGet(ID_STR_BACK), 0, MENU_PROMPT_GET_FOCUS);
	}
	#endif

	menuXOff=xoff;
	menuYOff=yoff;
}

/**************************************************************************
 *                                                                        *
 *  Function Name: menuProcDisp                                           *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments: None                                                       *
 *                                                                        *
 *  Returns:                                                              *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
void menuProcDisp (void)
{
	UINT8*	pMenu;
	UINT8	icon;
	UINT8	nodeItem = 0;
	UINT8	subItem=0;
	UINT8	selItem;
	UINT8	layer = 0;
	UINT8	item = 0;
	UINT8	line, col;
	UINT16	i;
	sp1kDispCapabDesc_t dispCap;
	UINT32	menuPos;
	UINT8	xpos=1;
	UINT8	ypos=1;
	UINT8	attr=0;
	PBFile_t pFileInfo;
	UINT8 OsdMaxX, OsdMaxY;

	sp1kOsdLayoutAttrGet(&OsdMaxX, &OsdMaxY);

	#if 1
	sp1kDispCapabilityGet(sp1kDispDevActGet(), &dispCap);
	menuPos = menuProcCurrPosGet();

	#if 1
	/* Init the menu display buffer data */
	for (i=0; i<256; i++)
	{
		if ((appPanelTypeGet() == 0) && ((i%OsdMaxX) == 0))
			idxBuf[i] = 0x0c;
		else
			idxBuf[i] = ' ';
		attrBuf[i] = 0;
	}
	#endif

	#if 1
	 /* Highlight the tab */
	/* Display the tab header */
	layer = menuProcLayerGet();
	if ((menuPos >= MENU_MARK_EXPOSURE_FIRST) && (menuPos < MENU_MARK_EXPOSURE_OVER))
	{
		menuHeaderDisp(MENU_HEADER_OFF);
	}
	else if ((menuPos >= MENU_MARK_RTC_FIRST) && (menuPos < MENU_MARK_RTC_OVER))
	{
		menuHeaderDisp(MENU_HEADER_OFF);
	}
	else if ((menuPos == MENU_MARK_ROTATE_ROTATE) || (menuPos == MENU_MARK_ROTATE_SAVE) || (menuPos == MENU_MARK_ROTATE_BACK) ||
			(menuPos == MENU_MARK_MEMO_ADD) || (menuPos == MENU_MARK_MEMO_DELETE) ||
			(menuPos == MENU_MARK_FORMAT_YES) || (menuPos == MENU_MARK_FORMAT_NO) ||
			(menuPos == MENU_MARK_RESET_YES) || (menuPos == MENU_MARK_RESET_NO))
	{
		menuHeaderDisp(MENU_HEADER_OFF);
	}
	else if (layer < 3)
	{
		if ((menuPos >= MENU_MARK_SETUP) && (menuPos < MENU_MARK_SETUP_OVER))
		{
			menuHeaderDisp(MENU_HEADER_SETUP);
		}
		else
		{
			menuHeaderDisp(MENU_HEADER_FUNCTION);
		}
	}
	else
	{
		menuHeaderDisp(MENU_HEADER_OFF);
	}
	#endif

	if ((menuPos >= MENU_MARK_EXPOSURE_FIRST) && (menuPos < MENU_MARK_EXPOSURE_OVER))
	{
		layer = menuProcLayerGet();
		menuLayerSizeGet(layer, &line, &col);
		item = menuProcCurrItemGet(layer);
		pMenu = menuProcPtrGet(layer, item);
		icon = menuProcIconIDGet(layer, item);

		nodeItem = menuProcNodeItemGet(layer, item);
		menuStrDisp((col-6)/2, line-2, "EV", 2, OSD_ATTR_COLOR_WHITE | OSD_ATTR_MODE_HALFTONE | OSD_ATTR_BACK_EN);
		menuStrDisp((col-6)/2+2, line-2, pMenu, 4, OSD_ATTR_COLOR_WHITE | OSD_ATTR_MODE_HALFTONE | OSD_ATTR_BACK_EN);
		menuStrDisp((col-13)/2, line-1, exposure, 13, OSD_ATTR_COLOR_WHITE);
		menuStrDisp((col-13)/2+item, line-1, &exposure[item], 1, OSD_ATTR_COLOR_BLUE);

		menuPromptDisp(MENU_PROMPT_OK_ON | MENU_PROMPT_MENU_ON);
	}
	else if ((menuPos >= MENU_MARK_RTC_FIRST) && (menuPos < MENU_MARK_RTC_OVER))
	{
		layer = menuProcLayerGet();
		item = 0;
		menuLayerSizeGet(layer, &line, &col);

		nodeItem = menuProcNodeItemGet(layer, item);

		#if 1
		for(i=0; i<nodeItem; i++,item++)
		{
			subItem = menuProcSubItemGet(layer, menuDateItemConv(item));
			if (subItem)
			{
				selItem = menuProcParaGet (layer, menuDateItemConv(item));
				pMenu = menuProcChildPtrGet(layer, menuDateItemConv(item), selItem);
				if (menuProcCurrItemGet(layer) == menuDateItemConv(item))
				{
					xpos += menuStrDisp(xpos, ypos, pMenu, 0, MENU_STR_GET_FOCUS);
					//menuStrDisp(xpos-1, ypos-1, "\x04", 0, OSD_ATTR_COLOR_BLACK);
					//menuStrDisp(xpos-1, ypos+1, "\x05", 0, OSD_ATTR_COLOR_BLACK);
				}
				else
				{
					xpos += menuStrDisp(xpos, ypos, pMenu, 0, MENU_STR_LOST_FOCUS);
				}
				if ((item == 0) || (item == 1))
					xpos += menuStrDisp(xpos, ypos, "/", 0, MENU_STR_LOST_FOCUS);
				else if (item == 3)
					xpos += menuStrDisp(xpos, ypos, ":", 0, MENU_STR_LOST_FOCUS);
				else if (item == 4)
				{
					xpos = 4;
					ypos += 2;
				}
				else
					xpos++;
			}
		}
		#endif
		menuPromptDisp(MENU_PROMPT_OK_ON | MENU_PROMPT_MENU_ON);
	}
	else if (((menuPos >= MENU_MARK_SLIDE_FIRST) && (menuPos < MENU_MARK_SLIDE_OVER)) ||
			((menuPos >= MENU_MARK_SOUND_FIRST) && (menuPos < MENU_MARK_SOUND_OVER)))
	{
		layer = 2;
		item = 0;

		menuLayerSizeGet(layer, &line, &col);

		nodeItem = menuProcNodeItemGet(layer, item);
		nodeItem -= menuProcScrollGet(layer);;

		if (nodeItem > line)
			nodeItem = line;
		item = menuProcScrollGet(layer);

		for(i=0; i<nodeItem; i++,item++)
		{
			pMenu = menuProcPtrGet(layer, item);
			subItem = menuProcSubItemGet(layer, item);

			if (!menuProcIsActive(layer, item))
			{
				menuStrDisp(0, i, pMenu, col-6, MENU_STR_DISABLE);
				menuStrDisp(col-6, i, " ", 6, MENU_ICON_LOST_FOCUS);
				if (subItem)
				{
					selItem = menuProcParaGet (layer, item);
					pMenu = menuProcChildPtrGet(layer, item, selItem);
					menuStrDisp(col-5, i, pMenu, 5, MENU_STR_DISABLE);
				}
			}
			else if (menuProcCurrItemGet(layer) == item)
			{
				menuStrDisp(0, i, pMenu, col-6, MENU_STR_GET_FOCUS);
				menuStrDisp(col-6, i, " ", 6, MENU_ICON_LOST_FOCUS);
				if (subItem)
				{
					selItem = menuProcParaGet (layer, item);
					pMenu = menuProcChildPtrGet(layer, item, selItem);
					menuStrDisp(col-5, i, pMenu, 5, MENU_ICON_GET_FOCUS);
				}
			}
			else
			{
				menuStrDisp(0, i, pMenu, col-6, MENU_STR_LOST_FOCUS);
				menuStrDisp(col-6, i, " ", 6, MENU_ICON_LOST_FOCUS);
				if (subItem)
				{
					selItem = menuProcParaGet (layer, item);
					pMenu = menuProcChildPtrGet(layer, item, selItem);
					menuStrDisp(col-5, i, pMenu, 5, MENU_ICON_LOST_FOCUS);
				}
			}
		}

		for(; i<line; i++)
		{
			menuStrDisp(0, i, " ", col, MENU_STR_LOST_FOCUS);
		}

		menuPromptDisp(MENU_PROMPT_OK_ON | MENU_PROMPT_MENU_ON);
	}
	else if ((menuPos == MENU_MARK_ROTATE_ROTATE) || (menuPos == MENU_MARK_ROTATE_SAVE) || (menuPos == MENU_MARK_ROTATE_BACK) ||
			(menuPos == MENU_MARK_MEMO_ADD) || (menuPos == MENU_MARK_MEMO_DELETE) ||
			(menuPos == MENU_MARK_FORMAT_YES) || (menuPos == MENU_MARK_FORMAT_NO) ||
			(menuPos == MENU_MARK_RESET_YES) || (menuPos == MENU_MARK_RESET_NO))
	{
		layer = 3;
		item = 0;
		menuLayerSizeGet(layer, &line, &col);

		layer = menuProcLayerGet();
		nodeItem = menuProcNodeItemGet(layer, item);
		nodeItem -= menuProcScrollGet(layer);;

		if (nodeItem > line)
			nodeItem = line;
		item = menuProcScrollGet(layer);

		for(i=0; i<nodeItem; i++,item++)
		{
			pMenu = menuProcPtrGet(layer, item);
			icon = menuProcIconIDGet(layer, item);

			if (!menuProcIsActive(layer, item))
			{
				menuStrDisp(2, i + (line - nodeItem), pMenu, col-4, MENU_STR_DISABLE);
			}
			else if (menuProcCurrItemGet(layer) == item)
			{
				menuStrDisp(2, i + (line - nodeItem), pMenu, col-4, MENU_STR_GET_FOCUS);
			}
			else
			{
				menuStrDisp(2, i + (line - nodeItem), pMenu, col-4, MENU_STR_LOST_FOCUS);
			}
		}

		/*if ((menuPos == MENU_MARK_DELETE_SINGLE_YES) || (menuPos == MENU_MARK_DELETE_SINGLE_NO))
		{
			pMenu = menuStrGet(ID_STR_DELETE_THIS_IMAGE_);
		}
		else*/
		{
			item = menuProcCurrItemGet(layer-1);
			pMenu = menuProcPtrGet(layer-1, item);
		}
		menuStrDisp(0, line-nodeItem-1, pMenu, col, MENU_TAB_GET_FOCUS);

		menuPromptDisp(MENU_PROMPT_OK_ON | MENU_PROMPT_MENU_OFF);
	}
	#if 1
	/* Display the setting menu */
	else if (menuProcLayerGet() == 0)
	{
		layer = 1;
		item = 0;
		menuLayerSizeGet(layer, &line, &col);

		nodeItem = menuProcNodeItemGet(layer, item);
		nodeItem -= menuProcScrollGet(layer);

		if (nodeItem > line)
			nodeItem = line;
		item = menuProcScrollGet(layer);

		for(i=0; i<nodeItem; i++,item++)
		{
			pMenu = menuProcPtrGet(layer, item);
			icon = menuProcIconIDGet(layer, item);
			subItem = menuProcSubItemGet(layer, item);
			if (subItem > 0)
			{
				selItem = menuProcParaGet (layer, item);
				icon = menuProcChildIconIDGet(layer, item, selItem);
			}
			if (menuProcIsActive(layer, item))
			{
				menuStrDisp(0, i, pMenu, col-2, MENU_ICON_LOST_FOCUS);
				menuIconDisp(col-2, i, icon, MENU_ICON_LOST_FOCUS);
			}
			else
			{
				menuStrDisp(0, i, pMenu, col-2, MENU_STR_DISABLE);
				menuIconDisp(col-2, i, icon, MENU_ICON_DISABLE);
			}
		}
		for(; i<line; i++)
		{
			menuStrDisp(0, i, " ", col-2, MENU_STR_LOST_FOCUS);
			menuIconDisp(col-2, i, ID_ICON_NONE, MENU_ICON_LOST_FOCUS);
		}

		menuPromptDisp(MENU_PROMPT_OK_ON | MENU_PROMPT_MENU_ON);
	}
	#endif

	#if 1 /* Highlight the setting menu */
	else if (menuProcLayerGet() == 1)
	{
		layer = 1;
		item = 0;
		menuLayerSizeGet(layer, &line, &col);

		nodeItem = menuProcNodeItemGet(layer, item);
		nodeItem -= menuProcScrollGet(layer);

		if (nodeItem > line)
			nodeItem = line;
		item = menuProcScrollGet(layer);

		for(i=0; i<nodeItem; i++,item++)
		{
			pMenu = menuProcPtrGet(layer, item);
			icon = menuProcIconIDGet(layer, item);
			subItem = menuProcSubItemGet(layer, item);
			if (subItem > 0)
			{
				selItem = menuProcParaGet (layer, item);
				icon = menuProcChildIconIDGet(layer, item, selItem);
			}

			if (!menuProcIsActive(layer, item))
			{
				menuStrDisp(0, i, pMenu, col-2, MENU_STR_DISABLE);
				menuIconDisp(col-2, i, icon, MENU_ICON_DISABLE);
			}
			else if (menuProcCurrItemGet(layer) == item)
			{
				menuStrDisp(0, i, pMenu, col-2, MENU_STR_GET_FOCUS);
				menuIconDisp(col-2, i, icon, MENU_ICON_GET_FOCUS);
			}
			else
			{
				menuStrDisp(0, i, pMenu, col-2, MENU_STR_LOST_FOCUS);
				menuIconDisp(col-2, i, icon, MENU_ICON_LOST_FOCUS);
			}
		}
		for(; i<line; i++)
		{
			menuStrDisp(0, i, " ", col, MENU_STR_LOST_FOCUS);
		}

		menuPromptDisp(MENU_PROMPT_OK_ON | MENU_PROMPT_MENU_ON);
	}
	#endif

	#if 1 /* Highlight the option menu */
	else if (menuProcLayerGet() == 2)
	{
		layer = 2;
		item = 0;

		menuLayerSizeGet(layer, &line, &col);

		nodeItem = menuProcNodeItemGet(layer, item);
		nodeItem -= menuProcScrollGet(layer);;

		if (nodeItem > line)
			nodeItem = line;
		item = menuProcScrollGet(layer);

		for(i=0; i<nodeItem; i++,item++)
		{
			if((menuPos >= MENU_MARK_LANGUAGE_FIRST) && (menuPos < MENU_MARK_LANGUAGE_OVER))
			{
				if(item == 5)
					pMenu = chinese_s;
				else if(item == 6)
					pMenu = chinese_t;
				else
					pMenu = menuProcPtrGet(layer, item);
			}
			else
				pMenu = menuProcPtrGet(layer, item);
			icon = menuProcIconIDGet(layer, item);

			if (!menuProcIsActive(layer, item))
			{
				if((menuPos >= MENU_MARK_PLAYBACK) && (menuPos < MENU_MARK_PLAYBACK_OVER))
				{
					menuStrDisp(0, i, pMenu, col, MENU_STR_DISABLE);
				}
				else
				{
					menuStrDisp(2, i, " ", 1, MENU_STR_LOST_FOCUS);
					menuStrDisp(3, i, pMenu, col-3, MENU_STR_DISABLE);
					menuIconDisp(0, i, icon, MENU_ICON_DISABLE);
				}
			}
			else if (menuProcCurrItemGet(layer) == item)
			{
				if((menuPos >= MENU_MARK_PLAYBACK) && (menuPos < MENU_MARK_PLAYBACK_OVER))
				{
					menuStrDisp(0, i, pMenu, col, MENU_STR_GET_FOCUS);
				}
				else
				{
					menuStrDisp(2, i, " ", 1, MENU_STR_LOST_FOCUS);
					menuStrDisp(3, i, pMenu, col-3, MENU_STR_GET_FOCUS);
					menuIconDisp(0, i, icon, MENU_ICON_GET_FOCUS);
				}
			}
			else
			{
				if((menuPos >= MENU_MARK_PLAYBACK) && (menuPos < MENU_MARK_PLAYBACK_OVER))
				{
					menuStrDisp(0, i, pMenu, col, MENU_STR_LOST_FOCUS);
				}
				else
				{
					menuStrDisp(2, i, " ", 1, MENU_STR_LOST_FOCUS);
					menuStrDisp(3, i, pMenu, col-3, MENU_STR_LOST_FOCUS);
					menuIconDisp(0, i, icon, MENU_ICON_LOST_FOCUS);
				}
			}
		}

		for(; i<line; i++)
		{
			menuStrDisp(0, i, " ", col, MENU_STR_LOST_FOCUS);
		}

		menuPromptDisp(MENU_PROMPT_OK_ON | MENU_PROMPT_MENU_ON);
	}
	#endif

	#if 1 /* Highlight the option menu */
	else if (menuProcLayerGet() == 3)
	{
		layer = 3;
		item = 0;

		menuLayerSizeGet(layer, &line, &col);

		nodeItem = menuProcNodeItemGet(layer, item);
		nodeItem -= menuProcScrollGet(layer);;

		if (nodeItem > line)
			nodeItem = line;
		item = menuProcScrollGet(layer);

		for(i=0; i<nodeItem; i++,item++)
		{
			pMenu = menuProcPtrGet(layer, item);
			icon = menuProcIconIDGet(layer, item);

			if (!menuProcIsActive(layer, item))
			{
				menuStrDisp(2, i + (line - nodeItem), pMenu, col-4, MENU_STR_DISABLE);
			}
			else if (menuProcCurrItemGet(layer) == item)
			{
				menuStrDisp(2, i + (line - nodeItem), pMenu, col-4, MENU_STR_GET_FOCUS);
			}
			else
			{
				menuStrDisp(2, i + (line - nodeItem), pMenu, col-4, MENU_STR_LOST_FOCUS);
			}
		}

		if ((menuPos == MENU_MARK_DELETE_SINGLE_YES) || (menuPos == MENU_MARK_DELETE_SINGLE_NO))
		{
			pMenu = menuStrGet(ID_STR_DELETE_THIS_FILE_);
		}
		else if ((menuPos == MENU_MARK_DELETE_ALL_YES) || (menuPos == MENU_MARK_DELETE_ALL_NO))
		{
			pMenu = menuStrGet(ID_STR_DELETE_ALL_FILE_);
		}
		else if ((menuPos == MENU_MARK_PROTECT_SINGLE_YES) || (menuPos == MENU_MARK_PROTECT_SINGLE_NO))
		{
			sp1kPbFileInfoGet(sp1kPbFileIndexByOrderGet(pbFile.dwIndex), &pFileInfo);
			if((pFileInfo.FileAttrib & 0x03) == 1)
				pMenu = menuStrGet(ID_STR_UNPROTECT_FILE_);
			else
				pMenu = menuStrGet(ID_STR_PROTECT_FILE_);
		}
		else if ((menuPos == MENU_MARK_PROTECT_ALL_YES) || (menuPos == MENU_MARK_PROTECT_ALL_NO))
		{
			pMenu = menuStrGet(ID_STR_PROTECT_ALL_);
		}
		else if ((menuPos == MENU_MARK_UNPROTECT_ALL_YES) || (menuPos == MENU_MARK_UNPROTECT_ALL_NO))
		{
			pMenu = menuStrGet(ID_STR_UNPROTECT_ALL_);
		}
		else
		{
			item = menuProcCurrItemGet(layer-1);
			pMenu = menuProcPtrGet(layer-1, item);
		}
		menuStrDisp(0, line-nodeItem-1, pMenu, col, MENU_TAB_GET_FOCUS);

		menuPromptDisp(MENU_PROMPT_OK_ON | MENU_PROMPT_MENU_OFF);
	}
	#endif
	sp1kOsdPageDrawUpdate(idxBuf,attrBuf);
	#endif
}

